package com.example.homework.api

import android.util.Log
import com.example.homework.models.Photo
import com.example.homework.utils.CONSTANTS.Companion.LOG_TAG
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext

object MarsPhotosService {

    suspend fun getPhotos(page: Int): List<Photo> {
        return try {
            withContext(Dispatchers.IO) {
                delay(5000)
                MarsPhotosApi.getPhotosApi.getPhotos(page).photos
            }
        } catch (ex: Exception) {
            Log.d(LOG_TAG, "Error fetching photos: ${ex.message}")
            listOf()
        }
    }
}